using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using AlphaWebsite.Models;

namespace AlphaWebsite.Controllers
{   
    public class BudgetItemsController : Controller
    {
		private readonly IBudgetCategoryRepository budgetcategoryRepository;
		private readonly IUserWeddingPlanRepository userweddingplanRepository;
		private readonly IBudgetItemsRepository budgetitemsRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public BudgetItemsController() : this(new BudgetCategoryRepository(), new UserWeddingPlanRepository(), new BudgetItemsRepository())
        {
        }

        public BudgetItemsController(IBudgetCategoryRepository budgetcategoryRepository, IUserWeddingPlanRepository userweddingplanRepository, IBudgetItemsRepository budgetitemsRepository)
        {
			this.budgetcategoryRepository = budgetcategoryRepository;
			this.userweddingplanRepository = userweddingplanRepository;
			this.budgetitemsRepository = budgetitemsRepository;
        }

        //
        // GET: /BudgetItems/

        public ViewResult Index()
        {
            return View(budgetitemsRepository.AllIncluding(budgetitems => budgetitems.BudgetCategory, budgetitems => budgetitems.UserWeddingPlan));
        }

        //
        // GET: /BudgetItems/Details/5

        public ViewResult Details(System.Guid id)
        {
            return View(budgetitemsRepository.Find(id));
        }

        //
        // GET: /BudgetItems/Create

        public ActionResult Create()
        {
			ViewBag.PossibleBudgetCategories = budgetcategoryRepository.All;
			ViewBag.PossibleUserWeddingPlans = userweddingplanRepository.All;
            return View();
        } 

        //
        // POST: /BudgetItems/Create

        [HttpPost]
        public ActionResult Create(BudgetItems budgetitems)
        {
            if (ModelState.IsValid) {
                budgetitemsRepository.InsertOrUpdate(budgetitems);
                budgetitemsRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleBudgetCategories = budgetcategoryRepository.All;
				ViewBag.PossibleUserWeddingPlans = userweddingplanRepository.All;
				return View();
			}
        }
        
        //
        // GET: /BudgetItems/Edit/5
 
        public ActionResult Edit(System.Guid id)
        {
			ViewBag.PossibleBudgetCategories = budgetcategoryRepository.All;
			ViewBag.PossibleUserWeddingPlans = userweddingplanRepository.All;
             return View(budgetitemsRepository.Find(id));
        }

        //
        // POST: /BudgetItems/Edit/5

        [HttpPost]
        public ActionResult Edit(BudgetItems budgetitems)
        {
            if (ModelState.IsValid) {
                budgetitemsRepository.InsertOrUpdate(budgetitems);
                budgetitemsRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleBudgetCategories = budgetcategoryRepository.All;
				ViewBag.PossibleUserWeddingPlans = userweddingplanRepository.All;
				return View();
			}
        }

        //
        // GET: /BudgetItems/Delete/5
 
        public ActionResult Delete(System.Guid id)
        {
            return View(budgetitemsRepository.Find(id));
        }

        //
        // POST: /BudgetItems/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(System.Guid id)
        {
            budgetitemsRepository.Delete(id);
            budgetitemsRepository.Save();

            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing) {
                budgetcategoryRepository.Dispose();
                userweddingplanRepository.Dispose();
                budgetitemsRepository.Dispose();
            }
            base.Dispose(disposing);
        }
    }
}

